package com.homedo.odin.solution.enumcode;

import lombok.Getter;
import org.apache.commons.lang.ArrayUtils;

@Getter
public enum UserTypeEnum {

    COMMON_USER(0, "普通用户"),
    EXPERT_USER(1, "专家用户"),
    BRAND_USER(2, "品牌用户");

    private int key;
    private String value;

    private UserTypeEnum(int key, String value) {
        this.value = value;
        this.key = key;
    }

    // 普通方法
    public static String getName(int key) {
        for (UserTypeEnum b : UserTypeEnum.values()) {
            if (b.getKey() == key) {
                return b.value;
            }
        }
        return null;
    }

    public static Integer getKey(String name) {
        int key = 0;
        for (UserTypeEnum p : UserTypeEnum.values()) {
            key = p.getKey();
            if (getName(key).equals(name)) {
                return key;
            }
        }
        return 0;
    }

    public String getValue() {
        return value;
    }

    public int getKey() {
        return key;
    }

    public static boolean validateType(int type) {
        return ArrayUtils.contains(new int[]{COMMON_USER.getKey(), EXPERT_USER.getKey(), BRAND_USER.getKey()}, type);
    }

}
